import store from "@/store/index";
import quinn from "@/utils/quinn";
import {API_HOST, IMG_HOST, $acc} from "@/assets/js/define.js";
import {
    FINANCE_TYPE_STATUS,
    FINANCE_TYPE_TAG_STATUS,
    EXTRA_ORDER_STATUS,
    EXTRA_ORDER_TAG_STATUS,
    statusRenderMap,
    STATUS_TAG,
    AFTERSALE_TAG,
    EXTRA_TAG,
    QUOTE_STATUS,
    INOUT_TAG_STATUS,
    ORDER_STATUS,
    ORDER_STATUS_BTN,
    ORDER_TAG_STATUS,
    CLASSIFY_STATUS,
    INOUT_STATUS,
    PRODUCT_STATUS,
    ORDER_STATUS_COLOR,
    areaColumn,
    inventoryColumn,
    colorGrey,
    colorBlue,
    colorRed,
    colorOrange,
    colorGreen,
    widthxs,
    widthsm,
    widthdf,
    widthlg,
    widthxl,
    widthxxl,
    widthxsl,
    widthssl,
    sortIndex,
    createdColumn,
    updatedColumn,
    _h,
    _tag,
    render,
    orderStatusRender,
    statusRender,
    directoryColumn,
    goodsFeeColumn,
    installFeeColumn,
    hotelFeeColumn,
    trafficFeeColumn,
    otherFeeColumn,
} from "./params";

const {authority = []} = quinn.getStorage("userDatav3") || store.state.userData || {};
const {authorityList = []} = quinn.getStorage("userDatav3") || store.state.userData || {};
let materials = [{label: "单位", prop: "unit", minWidth: widthdf}];
if (authority.includes(100)) {
    materials = [
        {label: "入库量", prop: "inCount", minWidth: widthdf},
        {
            label: "出库量", prop: "outCount", minWidth: widthdf,
            render: function (h, scope) {
                const {column, row} = scope;
                return h("span", {}, row.inCount ? row.inCount - row.count + row.checkCount : '暂无数据');
            },
        },
        {label: "平仓", prop: "checkCount", minWidth: widthdf},
        {
            label: '可用店铺', prop: "storeInventoryCount", minWidth: widthdf, render: function (h, scope) {
                const {column, row} = scope;
                return h("div",
                    {},
                    Math.floor(row.count / row.storeAverageUseCount) == 'Infinity' ? '暂无数据' : Math.floor(row.count / row.storeAverageUseCount),
                    // row.storeAverageUseCount == 0 ? '暂无数据'  : Math.floor(row.count / row.storeAverageUseCount)
                );
            }
        },
        {
            label: "库存状态", prop: "outCount", minWidth: widthdf,
            render: function (h, scope) {
                const {column, row} = scope;
                const statusText = row.warehouseId == 1 || row.warehouseId == 10 ? Math.floor(row.count / row.storeAverageUseCount) >= 50 ? "正常" : "预警" : Math.floor(row.count / row.storeAverageUseCount) >= 30 ? "正常" : "预警";
                return h("div",
                    {
                        style: {
                            color: statusText == '预警' ? '#303e9d' : '#000',
                            fontWeight: statusText == '缺货' ? '800' : '400',
                            cursor: 'pointer'
                        }
                    },
                    statusText
                );
            },
        },
        {label: "售价", prop: "salePrice", minWidth: widthdf},
        {label: "成本价", prop: "price", minWidth: widthdf},
        ...materials,
    ];
}

export const Materials = [
    sortIndex,
    {label: "材料编码", prop: "materialId", minWidth: widthxl},
    {label: "材料名称", prop: "materialName", minWidth: widthxsl},
    {label: "规格", prop: "norm", minWidth: widthdf},
    {label: "色号", prop: "color", minWidth: widthdf},

    ...materials,
];

export const ProcureMaterials = [
    ...Materials,
    {label: "采购数量", prop: "count", minWidth: widthdf},
    {label: "已入库", prop: "inCount", minWidth: widthdf},
];

const getOrderColumns = () => {
    let res = [];
    if (authority.includes(105))
        res = [
            {
                label: "成本价",
                prop: "costPrice",
                fixed: "right",
                minWidth: widthdf,
            },
            {label: "利润", prop: "profit", fixed: "right", minWidth: widthdf},
        ];
    return res;
};

const _imgRender = function (h, scope) {
    const {column, row} = scope;
    const value = row[column.property];
    let imgList = [];
    if (Array.isArray(value)) {
        try {
            imgList = value.filter((e) => e).map((e) => IMG_HOST + e);
        } catch (e) {
        }
    } else if ((value || "").includes(","))
        imgList = value
            .split(",")
            .filter((e) => e)
            .map((e) => IMG_HOST + e);
    else if (value) imgList.push(IMG_HOST + value);
    return imgList.length
        ? h(
            "el-image",
            {
                props: {
                    src: imgList[0],
                    fit: "cover",
                    previewSrcList: imgList,
                },
                style: {
                    width: "45px",
                    height: "30px",
                },
            },
            {}
        )
        : h("div", {}, "-");
};

export const ProcureList = [
    {label: "采购单编号", prop: "procureId", minWidth: widthdf},
    {label: "订单名称", prop: "orderName", minWidth: widthdf},
    ...ProcureMaterials.slice(1),
    {label: "供应商", prop: "supplierName", minWidth: widthdf},
    {label: "入库仓库", prop: "warehouseName", minWidth: widthdf},
    {label: "仓库联系人", prop: "warehouseContacts", minWidth: widthdf},
    {label: "采购金额", prop: "materialTotalPrice", minWidth: widthdf},
    {label: "已付款金额", prop: "procureTotalPayment", minWidth: widthdf},
    {label: "未付款", prop: "balancePayment", minWidth: widthdf},
    {
        label: "下单单据",
        prop: "procureVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "入库凭证",
        prop: "inVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "备注", prop: "remark", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {label: "操作人", prop: "userName", minWidth: widthdf},
    {
        label: "入库状态",
        prop: "arrivalStatus",
        fixed: "right",
        minWidth: widthsm,
        render: statusRenderMap({
            0: ["未入库", "danger"],
            1: ["部分入库", "info"],
            2: ["已入库", "success"],
        }),
    }, // 0未入库 1部分入库 2已入库
    {
        label: "付款状态",
        prop: "paymentStatus",
        fixed: "right",
        minWidth: widthsm,
        render: statusRenderMap({
            0: ["未付款", "danger"],
            1: ["已付款", "success"],
        }),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "200px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "edit", "编辑"),
                _h.call(this, h, colorGrey, "editProcureVouchers", "上传单据"),
                // _h.call(this, h, colorGrey, "ProcureMaterials", "查看明细"),
                _h.call(this, h, colorGrey, "download", "下载采购单"),
                _h.call(this, h, colorGreen, "uploadPayment", "付款录入"),
                _h.call(this, h, colorGreen, "paymentDetail", "付款明细"),
            ];
            if (row.paymentStatus != 1)
                actions.push(_h.call(this, h, colorGreen, "paymentDone", "付款完成"));
            if (row.arrivalStatus != 2)
                actions.push(
                    _h.call(this, h, colorBlue, "procureMaterialsIn", "操作入库"),
                    _h.call(this, h, colorBlue, "procureMaterialsInDone", "入库完成")
                );

            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const FinanceStatisticsIn = [
    sortIndex,
    {
        label: "关联订单",
        prop: "targetId",
        minWidth: widthdf,
    },
    {
        label: "费用类型",
        prop: "type",
        minWidth: widthdf,
    },
    {
        label: "来源类型",
        prop: "origin",
        minWidth: widthdf,
    },
    {
        label: "金额",
        prop: "amount",
        minWidth: widthdf,
    },
    {
        label: "情况说明",
        prop: "remark",
        minWidth: widthdf,
    },
    {
        label: "费用凭证",
        prop: "vouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "发起时间",
        prop: "buyTime",
        minWidth: widthdf,
    },
    // createdColumn,
];

export const FinanceStatisticsOut = FinanceStatisticsIn;

export const TransferList = [
    sortIndex,
    {
        label: "调货单编号",
        prop: "transferId",
        minWidth: widthdf,
    },
    {
        label: "订单名称",
        prop: "orderName",
        minWidth: widthdf,
    },
    {
        label: "调出仓库",
        prop: "outwarehouseName",
        minWidth: widthdf,
    },
    {
        label: "调出仓库联系人",
        prop: "outwarehouseContacts",
        minWidth: widthdf,
    },
    {
        label: "调入仓库",
        prop: "inwarehouseName",
        minWidth: widthdf,
    },
    {
        label: "调入仓库联系人",
        prop: "inwarehouseContacts",
        minWidth: widthdf,
    },
    // {
    //   label: "调货日期",
    //   prop: "调货日期",
    //   minWidth: widthdf,
    // },
    // {
    //   label: "调货人",
    //   prop: "调货人",
    //   minWidth: widthdf,
    // },
    {
        label: "是否已完成",
        prop: "status",
        minWidth: widthdf,
        render: statusRenderMap({
            0: ["未完成", "danger"],
            1: ["已完成", "success"],
        }),
    },
    {
        label: "入库凭证",
        prop: "inVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "到货凭证",
        prop: "arrivalVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    createdColumn,
    {
        label: "操作",
        prop: "actions",
        minWidth: "150px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "upload", "上传凭证"),
                _h.call(this, h, colorGreen, "TransferMaterials", "查看明细"),
                _h.call(this, h, colorBlue, "modifyInOutInventory", "出库"),
                _h.call(this, h, colorOrange, "transferIn", "入库"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const SupplierList = [
    sortIndex,
    {label: "供应商ID", prop: "supplierId", minWidth: widthdf},
    {label: "供应商名称", prop: "supplierName", minWidth: widthdf},
    {label: "银行", prop: "bank", minWidth: widthdf},
    {label: "银行账户", prop: "bankNumber", minWidth: widthdf},
    {label: "支行名称", prop: "accountName", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {
        label: "启用状态",
        prop: "status",
        fixed: "right",
        minWidth: widthsm,
        render: statusRenderMap({
            0: ["未启用", "danger"],
            1: ["已启用", "success"],
        }),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "120px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "edit", "编辑"),
                // _h.call(this, h, colorRed, "delete", "删除"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const TransferMaterials = [
    ...Materials,
    {label: "数量", prop: "count", minWidth: widthdf, fixed: "right"},
];
export const modifyCateList = [
    {label: "ID", prop: "classificationId", minWidth: '100px'},
    {label: "时间", prop: "createdTime", minWidth: '300px'},
    {label: "分类名", prop: "name", minWidth: '200px'},
    {
        label: "操作",
        prop: "actions",
        minWidth: "80px",
        // fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorRed, "delete", "删除"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
]
export const SaleList = [
    sortIndex,
    {label: "报货单编号", prop: "saleId", minWidth: widthdf},
    {label: "报货单名称", prop: "orderName", minWidth: widthdf},
    {label: "门店名称", prop: "storeName", minWidth: widthdf},
    {label: "配送地址", prop: "storeAddress", minWidth: widthdf},
    {label: "门店联系人", prop: "storeContacts", minWidth: widthdf},
    {label: "出货仓库", prop: "warehouseName", minWidth: widthdf},
    {label: "应收金额", prop: "paymentAmount", minWidth: widthdf},
    {label: "回款金额", prop: "receivedAmount", minWidth: widthdf},
    {
        label: "回款金额截图",
        prop: "paymentVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "备注", prop: "remark", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {
        label: "出库状态",
        prop: "outStatus",
        minWidth: widthdf,
        fixed: "right",
        render: statusRenderMap({
            0: ["未出库", "danger"],
            1: ["已出库", "success"],
        }),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "180px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "edit", "编辑"),
                _h.call(this, h, colorOrange, "import", "导入报货单"),
                _h.call(this, h, colorGreen, "SaleMaterials", "查看明细"),
                _h.call(this, h, colorBlue, "modifyInOutInventory", "出库"),
                // _h.call(this, h, colorBlue, "download", "下载销售单"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const AftersaleMaterials = [
    ...Materials,
    {label: "数量", prop: "count", minWidth: widthdf, fixed: "right"},
];

export const SaleMaterials = [
    ...Materials.slice(1),
    {
        label: "数量/操作",
        prop: "count",
        minWidth: widthdf,
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const {count, materialId, header = false} = row;
            const actions = [];
            if (header)
                actions.push(
                    _h.call(this, h, colorBlue, "downloadMaterials", `下载${materialId}`)
                );
            else actions.push(_h.call(this, h, "", "", count));
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const WarehouseList = [
    sortIndex,
    // { label: "区域", prop: "areaName", minWidth: widthdf },
    {label: "仓库ID", prop: "warehouseId", minWidth: widthdf},
    {label: "仓库名称", prop: "warehouseName", minWidth: widthdf},
    {label: "仓库管理员", prop: "warehouseManager", minWidth: widthdf},
    {label: "仓库联系人", prop: "warehouseContacts", minWidth: widthdf},
    {
        label: "仓库备用联系人",
        prop: "warehouseStandbyContacts",
        minWidth: widthdf,
    },
    createdColumn,
    updatedColumn,
    {
        label: "启用状态",
        prop: "status",
        fixed: "right",
        minWidth: widthsm,
        render: statusRenderMap({
            0: ["未启用", "danger"],
            1: ["已启用", "success"],
        }),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "120px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "edit", "编辑"),
                // _h.call(this, h, colorRed, "delete", "删除"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const MaterialList = [
    {label: '展开', type: 'expand', component: 'MateriaDetail', minWidth: '100px'},
    {label: '一级材料名', prop: 'name', minWidth: '150px'},
    {label: '创建时间', prop: 'createdTime', minWidth: '130px'},
    // ...Materials,
    {label: "供应商", prop: "supplierList", minWidth: '350px'},
    {label: '库存总和', prop: 'totalCount', minWidth: '200px'},
    {
        label: "操作",
        prop: "actions",
        minWidth: "80px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "edit", "编辑"),
                // _h.call(this, h, colorRed, "delete", "删除"),
            ];
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const ProcurePaymentList = [
    sortIndex,
    {label: "付款ID", prop: "procurePaymentId", minWidth: widthdf},
    {label: "付款金额", prop: "paymentAmount", minWidth: widthdf},
    {
        label: "付款金额截图",
        prop: "paymentVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    createdColumn,
    updatedColumn,
];

export const PaymentList = [
    sortIndex,
    {label: "订单ID", prop: "orderId", minWidth: widthssl},
    {label: "回款金额", prop: "amount", minWidth: widthssl},
    {
        label: "回款截图",
        prop: "prove",
        minWidth: widthdf,
        fixed: "right",
        render: _imgRender,
    },
];

const commonOrder = [
    sortIndex,
    {
        label: "ID",
        prop: "id",
        minWidth: widthxs,
        render: function (h, scope) {
            const {column, row} = scope;
            return h("div", {}, row?.orderId || row[column.property]);
        },
    },
    {label: "订单名称", prop: "storeName", minWidth: widthxl},
    {label: "发货日期", prop: "deliveryDate", minWidth: widthdf},
    {label: "发货地址", prop: "address", minWidth: widthxxl},
    {label: "客户联系方式", prop: "customPhone", minWidth: widthdf},
    createdColumn,
    ...(authority.includes(294)
        ? [{label: "应收金额", prop: "totalAmount", minWidth: widthxs}]
        : []),
    ...(authority.includes(293)
        ? [{label: "已回款总额", prop: "totalPayment", minWidth: widthxs}]
        : []),
    {
        label: "省份",
        prop: "area",
        minWidth: "60px",
        render: function (h, scope) {
            const {column, row} = scope;
            const value = row[column.property];
            const {areaMap} = store.state;
            return h("div", {}, areaMap[value] || "-");
        },
    },
    {
        label: "是否已出库",
        prop: "outStatus",
        minWidth: widthsm,
        render: function (h, scope) {
            const {column, row} = scope;
            const value = row[column.property];
            const outMap = {
                0: "待出库",
                1: "部分出库",
                2: "全部出库",
            };
            return h(
                "div",
                {
                    style: {
                        color: value ? (value == 1 ? colorBlue : colorOrange) : colorGrey,
                    },
                },
                outMap[value]
            );
        },
    },
    {
        label: "营业区原始图",
        prop: "storeImgs",
        minWidth: widthxs,
        render: _imgRender,
    },
    {
        label: "营业区转化图",
        prop: "cadImg",
        minWidth: widthxs,
        render: _imgRender,
    },
    {
        label: "仓库原始图",
        prop: "storageOriginImg",
        minWidth: widthxs,
        render: _imgRender,
    },
    {
        label: "仓库转化图",
        prop: "storageImg",
        minWidth: widthxs,
        render: _imgRender,
    },
];

const commonOrderFilter = (
    arr = [
        "sortIndex",
        "id",
        "storeName",
        "deliveryDate",
        "address",
        "customPhone",
        "createdTime",
    ]
) => {
    return commonOrder.filter((e) => arr.includes(e.prop));
};

export const OrderManage = [
    ...commonOrder,
    {
        label: "操作",
        prop: "actions",
        minWidth: "180px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [
                _h.call(this, h, colorGrey, "goodsDetail", "货架解析详情"),
                _h.call(this, h, colorGrey, "storageDetail", "仓储解析详情"),
            ];
            // actions.unshift(_h.call(this, h, colorBlue, "export", "导出Excel"));
            if (authority.includes(202))
                actions.unshift(_h.call(this, h, colorGreen, "addition", "杂项录入"));
            if (authority.includes(206))
                actions.unshift(
                    _h.call(this, h, colorGrey, "additionList", "杂项详情")
                );
            if (authority.includes(203))
                actions.unshift(_h.call(this, h, colorOrange, "payment", "回款录入"));
            if (authority.includes(205))
                actions.unshift(_h.call(this, h, colorGrey, "paymentList", "回款详情"));
            if (authority.includes(204))
                actions.unshift(_h.call(this, h, colorRed, "area", "发给仓库"));
            if (authority.includes(207))
                actions.unshift(_h.call(this, h, colorGrey, "edit", "编辑"));
            if (authority.includes(208))
                actions.unshift(_h.call(this, h, colorRed, "delete", "删除"));
            if (authority.includes(201))
                actions.unshift(_h.call(this, h, colorBlue, "CAD", "CAD上传"));
            if (authority.includes(177))
                actions.unshift(_h.call(this, h, colorGreen, "costs", "成本导出"));
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const ClassifyDetail = [
    sortIndex,
    {label: "套件编码", prop: "code", minWidth: widthxsl},
    {label: "套件名称", prop: "name", minWidth: widthxsl},
    {label: "套件数量", prop: "count", minWidth: widthxsl},
];

export const OrderWarehouse = [
    ...commonOrder.filter(
        (e) => !["totalAmount", "totalPayment"].includes(e.prop)
    ),
    {
        label: "操作",
        prop: "actions",
        minWidth: "260px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const actions = [
                _h.call(this, h, colorGrey, "goodsDetail", "货架解析详情"),
                _h.call(this, h, colorGrey, "storageDetail", "仓储解析详情"),
            ];
            // actions.unshift(_h.call(this, h, colorBlue, "export", "导出Excel"));
            const {authority} = store.state;
            actions.unshift(
                _h.call(this, h, colorGrey, "newOrderStorageList", "仓储货架清单下载")
            );
            actions.unshift(
                _h.call(this, h, colorGrey, "newOrderAdditionList", "杂项清单下载")
            );
            actions.unshift(
                _h.call(this, h, colorGrey, "newOrderMaterialList", "货架清单下载")
            );
            actions.unshift(_h.call(this, h, colorOrange, "installList", "安装列表"));
            actions.unshift(_h.call(this, h, colorOrange, "install", "安装"));
            if (authority.includes(209))
                actions.unshift(_h.call(this, h, colorRed, "delete", "删除"));
            if (row.outStatus != 2)
                actions.unshift(_h.call(this, h, colorBlue, "out", "出库"));
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const OrderAftersale = [
    ...commonOrderFilter(),
    {
        label: "售后原因",
        prop: "afterSaleTypeText",
        minWidth: "240px",
    },
    {
        label: "售后备注",
        prop: "remark",
        minWidth: widthxl,
    },
    {
        label: "售后图片",
        prop: "preSalesImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "售后完成图片",
        prop: "afterSalesImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "售后完成备注",
        prop: "finishRemark",
        minWidth: widthxl,
    },
    {label: "售后人员", prop: "afterSales", minWidth: widthxl},
    {label: "发车金额", prop: "departFee", minWidth: widthxsl},
    {
        label: "发车金额截图",
        prop: "departImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "安装费用", prop: "installFee", minWidth: widthxsl},
    {
        label: "安装费用截图",
        prop: "installImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "安装住宿费用", prop: "hotelFee", minWidth: widthxsl},
    {
        label: "安装住宿费用截图",
        prop: "hotelImg",
        minWidth: widthxl,
        render: _imgRender,
    },
    {label: "工作餐费用", prop: "foodFee", minWidth: widthxsl},
    {
        label: "工作餐费用截图",
        prop: "foodImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "交通费用", prop: "trafficFee", minWidth: widthxsl},
    {
        label: "交通费用截图",
        prop: "trafficImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "状态",
        prop: "status",
        minWidth: widthdf,
        fixed: "right",
        render: statusRender(AFTERSALE_TAG),
    },
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthxxl,
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [_h.call(this, h, colorGrey, "detail", "材料详情")];
            if (status == 0 && authority.includes(295))
                actions.unshift(_h.call(this, h, colorGreen, "done", "确认完成"));
            if (authority.includes(179))
                actions.push(_h.call(this, h, colorRed, "delete", "删除"));
            return h("div", {}, actions);
        },
    },
];

export const AdditionList = [
    sortIndex,
    {label: "材料ID", prop: "id", minWidth: widthxl},
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    // { label: "单价", prop: "price", minWidth: widthdf },
    {label: "数量", prop: "count", minWidth: widthdf, fixed: "right"},
];

export const AfterSaleDetail = AdditionList;

export const InstallList = [
    {label: "安装人员", prop: "installers", minWidth: widthxl},
    {label: "发车金额", prop: "departFee", minWidth: widthxsl},
    {
        label: "发车金额截图",
        prop: "departImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "安装费用", prop: "installFee", minWidth: widthxsl},
    {
        label: "安装费用截图",
        prop: "installImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "安装住宿费用", prop: "hotelFee", minWidth: widthxsl},
    {
        label: "安装住宿费用截图",
        prop: "hotelImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "工作餐费用", prop: "foodFee", minWidth: widthxsl},
    {
        label: "工作餐费用截图",
        prop: "foodImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "交通费用", prop: "trafficFee", minWidth: widthxsl},
    {
        label: "交通费用截图",
        prop: "trafficImg",
        minWidth: widthdf,
        render: _imgRender,
    },
];

export const OrderExtra = [
    sortIndex,
    // { label: "订单ID", prop: "id", minWidth: widthxxl },
    // { label: "订单名称", prop: "orderName", minWidth: widthxsl },
    {label: "售后金额", prop: "fee", minWidth: widthdf},
    {
        label: "售后理由",
        prop: "reason",
        minWidth: widthxsl,
        render: statusRender(EXTRA_TAG),
    },
    {label: "售后备注", prop: "remark", minWidth: widthxsl, showTip: true},
    {label: "创建人", prop: "creatorName", minWidth: widthdf},
    createdColumn,
    // updatedColumn,
    {
        label: "订单状态",
        prop: "status",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(EXTRA_ORDER_STATUS, EXTRA_ORDER_TAG_STATUS),
    },
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthxxl,
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [_h.call(this, h, colorGrey, "0", "查看材料")];
            if (status == 0) {
                actions.unshift(
                    _h.call(this, h, colorRed, "-1", "拒绝"),
                    _h.call(this, h, colorGreen, "1", "通过")
                );
            }
            return h("div", {}, actions);
        },
    },
];

export const ExbandColumn = [
    sortIndex,
    {label: "订单ID", prop: "id", minWidth: widthxxl},
    {label: "订单名称", prop: "orderName", minWidth: widthxsl},
    {label: "售后金额", prop: "fee", minWidth: widthdf},
    {
        label: "售后理由",
        prop: "reason",
        minWidth: widthxsl,
        render: statusRender(EXTRA_TAG),
    },
    {label: "售后备注", prop: "remark", minWidth: widthxsl, showTip: true},
    {label: "创建人", prop: "creatorName", minWidth: widthdf},
    createdColumn,
    // updatedColumn,
    {
        label: "订单状态",
        prop: "status",
        minWidth: widthsm,
        render: statusRender(EXTRA_ORDER_STATUS, EXTRA_ORDER_TAG_STATUS),
    },
];

export const OrderInstall = [
    sortIndex,
    {label: "订单ID", prop: "id", minWidth: widthxxl},
    {label: "订单名称", prop: "orderName", minWidth: widthxsl},
    goodsFeeColumn,
    installFeeColumn,
    hotelFeeColumn,
    trafficFeeColumn,
    otherFeeColumn,
    {
        label: "报装人",
        prop: "installers",
        minWidth: widthdf,
        render: function (h, scope) {
            const {column, row} = scope;
            return h("span", {}, row[column.property].join("、"));
        },
    },
    {label: "报装备注", prop: "description", minWidth: widthxsl, showTip: true},
    {label: "创建人", prop: "creatorName", minWidth: widthdf},
    createdColumn,
    // updatedColumn,
];

export const OrderFlow = [
    sortIndex,
    {label: "订单编号", prop: "orderId", minWidth: widthxxl},
    {label: "订单名称", prop: "orderName", minWidth: widthxsl},
    {label: "创建人", prop: "creatorName", minWidth: widthdf},
    createdColumn,
    // updatedColumn,
    {
        label: "订单状态",
        prop: "status",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(ORDER_STATUS, ORDER_TAG_STATUS),
    },
];

export const InventoryWarn = [
    sortIndex,
    areaColumn,
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    // { label: "套件", prop: "dirName", minWidth: widthxsl },
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    {label: "单价", prop: "price", minWidth: widthdf},
    createdColumn,
    // updatedColumn,
    inventoryColumn,
];

let saleKeys = [];
let saleAction = [
    {
        label: "操作",
        prop: "actions",
        minWidth: widthdf,
        fixed: "right",
        render: function (h, scope) {
            return _h.call(this, h, colorBlue, "modifyCount", "修改库存");
        },
    },
];
if ((authority || []).includes(191))
    saleKeys = [
        {label: "成本价", prop: "price", minWidth: widthdf},
        {label: "售价", prop: "salePrice", minWidth: widthdf},
    ];

if ((authority || []).includes(5)) saleAction = [];

export const InventoryDetail = [
    sortIndex,
    areaColumn,
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    {label: "套件", prop: "dirName", minWidth: widthxsl},
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    ...saleKeys,
    createdColumn,
    // updatedColumn,
    inventoryColumn,
    ...saleAction,
];
export const ExtraListColumn = [
    sortIndex,
    {label: "材料ID", prop: "id", minWidth: widthxl},
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    {label: "单价", prop: "price", minWidth: widthdf},
    {label: "数量", prop: "count", minWidth: widthdf, fixed: "right"},
];

export const InventoryRecordDetail = [
    sortIndex,
    {label: "材料ID", prop: "id", minWidth: widthxl},
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    {label: "单价", prop: "price", minWidth: widthdf},
    {label: "数量", prop: "count", minWidth: widthdf, fixed: "right"},
];

export const ProductManage = [
    sortIndex,
    {label: "材料ID", prop: "id", minWidth: widthxl},
    {label: "材料编码", prop: "productCode", minWidth: widthdf},
    {label: "材料名称", prop: "productName", minWidth: widthxsl},
    {
        label: "套件",
        prop: "directorys",
        minWidth: widthxsl,
        render: function (h, scope) {
            const {column, row} = scope;
            const value = (row[column.property] || []).map((e) => e.name);
            return h("span", {}, value.join("、"));
        },
    },
    {label: "规格", prop: "norms", minWidth: widthdf},
    {label: "单位", prop: "unit", minWidth: widthdf},
    {label: "色号", prop: "colour", minWidth: widthdf},
    {label: "单价", prop: "price", minWidth: widthdf},
    {label: "说明", prop: "description", width: widthxsl, showTip: true},
    createdColumn,
    updatedColumn,
    {
        label: "状态",
        prop: "materialStatus",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(PRODUCT_STATUS),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "200px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.materialStatus;
            return h("div", {}, [
                _h.call(this, h),
                status == 0
                    ? _h.call(this, h, colorBlue, "on", "上架")
                    : _h.call(this, h, colorOrange, "off", "下架"),
                _h.call(this, h, colorGreen, "qrcode", "库存码"),
                _h.call(this, h, colorRed, "delete", "删除"),
            ]);
        },
    },
];

export const InventoryRecord = [
    sortIndex,
    areaColumn,
    // { label: "材料编码", prop: "productCode", minWidth: widthdf },
    // { label: "材料名称", prop: "productName", minWidth: widthxsl },
    // { label: "套件", prop: "dirName", minWidth: widthdf },
    // { label: "规格", prop: "norms", minWidth: widthdf },
    // { label: "单位", prop: "unit", minWidth: widthdf },
    // { label: "色号", prop: "colour", minWidth: widthdf },
    // { label: "单价", prop: "price", minWidth: widthdf },
    {label: "拣货人员", prop: "sorter", minWidth: widthdf},
    {label: "操作人", prop: "creatorName", minWidth: widthxsl},
    createdColumn,
    updatedColumn,
    // inventoryColumn,
    {
        label: "发车照片",
        prop: "deliveryImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "送货单图",
        prop: "listImg",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "状态",
        prop: "status",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(INOUT_STATUS, INOUT_TAG_STATUS),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: "100px",
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            console.log(status);
            return h("div", {}, [
                status == 0
                    ? _h.call(this, h, colorGreen, "detail", "出库清单")
                    : _h.call(this, h, colorBlue, "detail", "入库清单"),
            ]);
        },
    },
];

export const ClassifyManage = [
    sortIndex,
    {label: "套件名称", prop: "name", minWidth: widthxsl},
    {label: "套件价格", prop: "salePrice", minWidth: widthxsl},
    {label: "创建人", prop: "creatorName", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {
        label: "状态",
        prop: "status",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: widthlg,
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            return h("div", {}, [
                _h.call(this, h),
                status == 0
                    ? _h.call(this, h, colorBlue, "on", "开启")
                    : _h.call(this, h, colorOrange, "off", "禁用"),
                _h.call(this, h, colorRed, "delete", "删除"),
            ]);
        },
    },
];

export const AccountManage = [
    sortIndex,
    {label: "用户ID", prop: "userId", minWidth: widthdf},
    {label: "姓名", prop: "userName", minWidth: widthdf},
    {label: "手机号码", prop: "phoneNum", minWidth: widthdf},
    {
        label: "角色",
        prop: "roleName",
        minWidth: widthdf,
    },
    createdColumn,
    updatedColumn,
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthxxl,
        action: [
            {
                text: "修改",
                type: "text",
                options: "edit",
            },
            // {
            //   text: "删除",
            //   type: "text",
            //   options: "delete",
            //   style: {
            //     color: colorRed,
            //   },
            // },
        ],
    },
];

export const RoleManage = [
    {label: "角色ID", prop: "id", minWidth: widthdf},
    {label: "角色权限", prop: "permission", minWidth: widthdf},
    {label: "角色名", prop: "name", minWidth: widthdf},
    {label: "角色描述", prop: "description", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {
        label: "状态",
        prop: "status",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(),
    },
    {
        label: "操作",
        prop: "",
        fixed: "right",
        action: [
            {
                text: "修改",
                type: "text",
                options: "edit",
            },
        ],
    },
];

export const InOutInOutList = [
    sortIndex,
    {label: "订单编号", prop: "targetId", minWidth: widthdf},
    {label: "订单名称", prop: "orderName", minWidth: widthdf},
    {label: "材料编码", prop: "materialId", minWidth: widthdf},
    {label: "仓库", prop: "warehouseName", minWidth: widthdf},
    {
        label: "出库凭证",
        prop: "outVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    createdColumn,
    // updatedColumn,
    {
        label: "订单类型",
        prop: "type",
        fixed: "right",
        minWidth: widthdf,
        render: statusRenderMap({
            sale: ["报货", "info"],
            transfer: ["调货", "danger"],
            afterSale: ["售后", "success"],
        }),
    },
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthsm,
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [];
            actions.push(_h.call(this, h, colorBlue, "InOutDetail", "出库明细"));
            return h("div", {}, actions);
        },
    },
];

let InventoryInventoryListArr = [

    ...Materials,
    createdColumn,
    // updatedColumn,
    // { label: "入库量", prop: "inCount", minWidth: widthdf },
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthlg,
        render: function (h, scope) {
            const {column, row} = scope;
            const {reason} = row;
            const actions = [];
            actions.push(_h.call(this, h, '#303e9d', "editLimit", "修改阈值"));
            return h("div", {}, actions);
        },
    },
];
InventoryInventoryListArr.splice(1, 0, {
    label: "仓库",
    prop: "warehouseName",
    minWidth: widthdf,
});
InventoryInventoryListArr.splice(
    6,
    0,
    {
        label: "库存数",
        prop: "count",
        minWidth: widthdf,
        render: function (h, scope) {
            const {column, row} = scope;
            const {limit, count} = row;
            if (count < limit)
                return h(
                    "div",
                    {
                        style: {color: "#303e9d", fontSize: "16px", fontWeight: "bold"},
                    },
                    count
                );
            return h("div", {}, count);
        },
    },
    // {
    //   label: "告警阈值",
    //   prop: "limit",
    //   minWidth: widthdf,
    // }
);
export const InventoryInventoryList = InventoryInventoryListArr;

export const InventoryInventoryAlarmList = InventoryInventoryList;
// {
//   "afterSaleId": "SH20240111231110",
//   "storeName": "龙湖店",
//   "reason": 1,
//   "handleMethod": "处理方式",
//   "refundAmount": null,
//   "isRestock": true,
//   "materialTotalPrice": 10000,
//   "materials": "[{\"id\":\"tjb-01\",\"count\":100},{\"id\":\"skt-01\",\"count\":200},{\"id\":\"skt-02\",\"count\":200}]",
//   "finishStatus": 0,
//   "targetId": "XS20240110161617",
//   "warehouseId": null,
//   "creator": 125758,
//   "remark": "备注",
//   "createdAt": "2024-01-11T15:11:10.000Z",
//   "updatedAt": "2024-01-11T15:11:10.000Z"
// }

export const AfterSaleAfterSaleList = [
    sortIndex,
    {label: "售后编号", prop: "afterSaleId", minWidth: widthdf},
    {label: "订单名称", prop: "orderName", minWidth: widthdf},
    {label: "关联订单", prop: "targetId", minWidth: widthdf},
    {label: "门店名称", prop: "storeName", minWidth: widthdf},
    {label: "售后仓库", prop: "warehouseName", minWidth: widthdf},
    {
        label: "售后原因",
        prop: "reason",
        minWidth: widthdf,
        render: function (h, scope) {
            const {column, row} = scope;
            const reason = row.reason;
            const {aftersaleReasonMap} = store.getters;
            return h("div", {}, aftersaleReasonMap[reason]);
        },
    },
    {label: "处理方式", prop: "handleMethod", minWidth: widthdf},
    // { label: "退款金额", prop: "refundAmount", minWidth: widthdf },
    {
        label: "是否有补货",
        prop: "isRestock",
        minWidth: widthdf,
        render: statusRenderMap({
            0: ["否", "info"],
            1: ["是", "success"],
        }),
    },
    {label: "材料款", prop: "materialTotalPrice", minWidth: widthdf},
    {
        label: "是否已完成",
        prop: "finishStatus",
        minWidth: widthdf,
        render: statusRenderMap({
            0: ["未完成", "info"],
            1: ["已完成", "success"],
        }),
    },
    createdColumn,
    updatedColumn,
    {
        label: "操作",
        prop: "actions",
        fixed: "right",
        minWidth: widthlg,
        render: function (h, scope) {
            const {column, row} = scope;
            const {reason} = row;
            const actions = [];
            actions.push(
                _h.call(this, h, colorGrey, "edit", "编辑"),
                _h.call(this, h, colorGreen, "AftersaleMaterials", "售后明细")
            );
            if ([1, 2, 4].includes(reason))
                actions.push(
                    _h.call(this, h, colorBlue, "modifyInOutInventory", "扣库存")
                );
            return h("div", {}, actions);
        },
    },
];
export const FinanceList = [
    sortIndex,
    {
        label: "报销类型",
        prop: "type",
        fixed: "right",
        minWidth: widthdf,
        render: statusRenderMap({
            sale: ["报货", "info"],
            transfer: ["调货", "success"],
            afterSale: ["售后", "danger"],
        }),
    },
    {label: "关联订单", prop: "targetId", minWidth: widthdf},
    {label: "报销金额", prop: "financeAmount", minWidth: widthdf},
    {
        label: "报销金额截图",
        prop: "financeVouchers",
        minWidth: widthdf,
        render: _imgRender,
    },
    {
        label: "处理状态",
        prop: "status",
        fixed: "right",
        minWidth: widthdf,
        render: statusRenderMap({
            0: ["未完成", "info"],
            1: ["已完成", "success"],
        }),
    },
    {label: "备注", prop: "remark", minWidth: widthdf},
    createdColumn,
    updatedColumn,
    {
        label: "操作",
        prop: "actions",
        minWidth: widthdf,
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [];
            if (status == 0)
                actions.push(_h.call(this, h, colorOrange, "done", "已完成"));
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

export const InOutDetail = [
    ...Materials,
    {label: "出库数", prop: "count", fixed: "right", minWidth: widthdf},
];

export const Finance = [
    ...commonOrderFilter(),
    {label: "已支付总金额", prop: "payAmount", minWidth: widthsm},
    {
        label: "付款凭证",
        prop: "payVoucher",
        minWidth: widthdf,
        render: _imgRender,
    },
    {label: "驳回备注", prop: "remark", width: widthssl},
    ...OrderAftersale.filter((e) =>
        [
            "departFee",
            "departImg",
            "installFee",
            "installImg",
            "hotelFee",
            "hotelImg",
            "foodFee",
            "foodImg",
            "trafficFee",
            "trafficImg",
        ].includes(e.prop)
    ),
    {
        label: "订单类型",
        prop: "type",
        minWidth: widthsm,
        fixed: "right",
        render: statusRender(FINANCE_TYPE_STATUS, FINANCE_TYPE_TAG_STATUS),
    },
    {
        label: "操作",
        prop: "actions",
        minWidth: widthdf,
        fixed: "right",
        render: function (h, scope) {
            const {column, row} = scope;
            const status = row.status;
            const actions = [];
            if (authority.includes(184) && status == 0)
                actions.push(_h.call(this, h, colorBlue, "financeDoneRef", "付款完成"));
            if (authority.includes(183) && status == 0)
                actions.push(
                    _h.call(this, h, colorOrange, "finaceRefuseRef", "付款驳回")
                );
            if (authority.some((e) => [182, 181, 180].includes(e)))
                actions.push(_h.call(this, h, colorRed, "delete", "删除"));
            return h(
                "div",
                {
                    style: {
                        display: "flex",
                        flexWrap: "wrap",
                    },
                },
                actions
            );
        },
    },
];

let newFinance = Finance.filter((e) => e.prop != "actions");
newFinance.push({
    label: "操作",
    prop: "actions",
    fixed: "right",
    minWidth: widthsm,
    render: function (h, scope) {
        const {column, row} = scope;
        const status = row.status;
        const actions = [];
        actions.push(_h.call(this, h, colorRed, "updateFinanceRef", "编辑"));
        return h("div", {}, actions);
    },
});

export const FinanceReject = newFinance;
